package com.baoxin.chenxixc4coach.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baoxin.chenxixc4coach.R;
import com.baoxin.chenxixc4coach.bean.Video;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

import java.util.List;

public class MyVideoAdapter extends RecyclerView.Adapter<MyVideoAdapter.Holder> {
    private List<Video> videoList;
    private Context context;

    public MyVideoAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<Video> videoList) {
        this.videoList = videoList;
    }

    static class Holder extends RecyclerView.ViewHolder {
        View item;
        ImageView thumbnail;
        TextView title;
        TextView info;
        TextView time;

        public Holder(View view) {
            super(view);
            item = view;
            thumbnail = view.findViewById(R.id.video_thumbnail);
            title = view.findViewById(R.id.video_title);
            info = view.findViewById(R.id.video_info);
            time = view.findViewById(R.id.video_time);
        }
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_video_item, parent, false);
        final Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        Video video = videoList.get(position);
        holder.title.setText(video.getTitle());
        holder.info.setText(video.getContent());
        holder.time.setText(video.getTime());
        Glide.with(context)
                .load(R.drawable.school)
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(25)))
                .into(holder.thumbnail);
    }

    @Override
    public int getItemCount() {
        return videoList.size();
    }
}
